﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.SystemConfig;
using AnQinFrameWorkAPI.Entity.SystemCore.View.SystemConfig;
using AnQinFrameWorkAPI.Service.SystemCore;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.SystemCore;

/// <summary>
///     全局配置API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "SystemCore")]
public class SystemConfigController : ControllerBase
{
    //业务接口
    private readonly SystemConfigService _systemConfigService;

    //构造注入
    public SystemConfigController(SystemConfigService systemConfigService)
    {
        _systemConfigService = systemConfigService;
    }

    /// <summary>
    ///     获取全局配置列表
    /// </summary>
    [ProducesResponseType(typeof(SystemConfigView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetSystemConfigList([FromQuery] SystemConfigSearchDTO systemConfigSearchDTO)
    {
        var response = await _systemConfigService.GetSystemConfigList(systemConfigSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增全局配置
    /// </summary>
    /// <params name="systemConfigAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddSystemConfig([FromBody] SystemConfigAddDTO systemConfigAddDTO)
    {
        var response = await _systemConfigService.AddSystemConfig(systemConfigAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑全局配置
    /// </summary>
    /// <params name="systemConfigUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutSystemConfig([FromBody] SystemConfigUpdateDTO systemConfigUpdateDTO)
    {
        var response = await _systemConfigService.PutSystemConfig(systemConfigUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除全局配置
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteSystemConfig([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _systemConfigService.DeleteSystemConfig(deleteDTO);
        return StatusCode(response.Status, response);
    }
}